import {getcates} from "../../request/api.js"
const state={
    oneList:[],
    twoList:[]
}
const mutations={
    changOneList(state,arr){
        state.oneList = arr
    },
    changeTwoList(state,arr){
        state.twoList = arr
    }
}
const actions={
    asyncOneList(context){
        getcates().then(res=>{
            context.commit("changOneList",res.data.list)
        context.commit("changeTwoList",res.data.list[0].children)
        })
        
    },
    asyncTwoList(context,index){
        // 第二种方式，我们只给状态层传过去一个index，状态层自己根据index查找对应的数据
        context.commit("changeTwoList",context.state.oneList[index].children)
      }
}
const getters={
    oneList(state){
        return state.oneList
      },
      twoList(state){
        return state.twoList
      }
}

export default{
    state,
    mutations,
    actions,
    getters,
    namespaced: true
}